<?php namespace system\model;
use houdunwang\model\Model;
class Link extends Model{
	//数据表
	protected $table = "link";

	//允许填充字段
	protected $allowFill = ['*' ];
	//自动验证
	protected $validate=[
		//['字段名','验证方法','提示信息',验证条件,验证时间]
          ['lname','isnull','链接名称不能为空',self::MUST_VALIDATE,self::MODEL_BOTH],
          ['logo', 'isnull','logo不能为空',self::MUST_VALIDATE,self::MODEL_BOTH],
          ['url', 'http','url不能为空',self::MUST_VALIDATE,self::MODEL_BOTH],
          ['sort', 'num:1,9999','排序不能为空',self::MUST_VALIDATE,self::MODEL_BOTH],
//        lname,logo,url,sort
	];
	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
          ['addtime','time','function',self::MUST_AUTO,self::MODEL_INSERT]
	];

    /**
     * 添加超链接
     * @return bool
     */
    public function addLink(){
        /**
         * 映射表结构
         */
          $this->lname=$_POST['lname'];
          $this->logo=$_POST['logo'];
          $this->url=$_POST['url'];
          $this->sort=$_POST['sort'];
          return $this->save();
    }
    /**
     * 修改超链接
     */
    public function  editLink(){
      /**
       * 映射表结构
       */
      $lid=$_POST['lid'];
      $ArticleModel=$this->where('lid',$lid)->first();
      $ArticleModel->lname=$_POST['lname'];
      $ArticleModel->logo = $_POST['logo'];
      $ArticleModel->url=$_POST['url'];
      $ArticleModel->sort=$_POST['sort'];
      return $ArticleModel->save();
    }
}